#! /usr/bin/env pike

int main() {
  string base = Stdio.read_file("bookmarklet.template");
  array files = map("index.html,toolbar.html,input.html"/",", Stdio.read_file);
  for (int i = 0; i < sizeof(files); i++)
    base = replace(base, "$"+(i+1), quote(files[i]));
  base = "javascript:" + Protocols.HTTP.http_encode_string(base);
  Stdio.write_file("bookmarklet.html","<a href='"+base+"'>jsenv</a>");
}

string quote(string js) {
  return replace(js - "\r", "\\\"\'\n"/1, "\\\\\\\"\\\'\\n"/2);
}